package com.kurumi.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kurumi.pojo.MedicalRecordPageIndex2016;
import com.kurumi.pojo.RespondResult;
import com.kurumi.query.MedicalRecordQuery;
import com.kurumi.service.MedicalRecordCheckService;
import com.kurumi.service.MedicalRecordPageIndexService;
import com.kurumi.service.MedicalRecordPageIndexWjtCheckService;
import com.kurumi.service.PageIndexRefService;
import com.kurumi.util.ListPagination;

@Controller
@RequestMapping("/medical_record_check")
public class MedicalRecordCheckController {

	@Autowired
	private MedicalRecordCheckService medicalRecordCheckService;
	
	@Autowired
	private MedicalRecordPageIndexService medicalRecordPageIndexService;
	
	@Autowired
	private MedicalRecordPageIndexWjtCheckService pageIndexWjtCheckService; 
	
	@Autowired
	private PageIndexRefService pageIndexRefService;
	
	@GetMapping("/page_index_check_page")
	public String pageIndexCheckCheck(Model model){
		return "check/page_index_check_page";
	}
	
	@GetMapping("/ajax_page_index_check")
	@ResponseBody
	public RespondResult ajaxMainDiseaseDiagCheck(MedicalRecordQuery params){
		RespondResult respondResult = null;
		
		try{
			List<Map<String,Object>> medicalRecords = new ArrayList<Map<String,Object>>();
			if(!params.queryUnEncodingEmpty()){
				/*medicalRecords = medicalRecordCheckService.pageIndexCheck(params);*/
				/*Map<String,Map<String,String>> pageIndexDectRefs = pageIndexRefService.getSimplePageIndex2016DectRefs();*/
				Map<String,Map<String,String>> pageIndexDectRefs = pageIndexRefService.getPageIndexWjtDectRefs();
				Map<String, Map<String, Object>> gbtDectRefs = pageIndexRefService.getGbtDectRefs();
				//List<MedicalRecordPageIndexInterface> pageIndexs = medicalRecordPageIndexService.getMedicalRecordPageIndexInterface(params);
				List<MedicalRecordPageIndex2016> pageIndexs = medicalRecordPageIndexService.getMedicalRecordPageIndex2016(params);
				medicalRecords = pageIndexWjtCheckService.pageIndexCheckWjt(pageIndexs, pageIndexDectRefs, gbtDectRefs);
			}
			params.setTotalCounts(medicalRecords.size());
			ListPagination list = new ListPagination<Map<String, Object>>(medicalRecords, params.getCurrentPage(), params.getPageSize());
			params.setQueryDatas(list.getList());
			respondResult = new RespondResult(true, RespondResult.successCode, null, params);
			
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(), "");
		}
		
		return respondResult;
	}
	
}
